<template>
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="username" {{d.entity.id?'disabled':''}} placeholder="例如：a123456"
                    value="{{d.entity.username||''}}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">登录名</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input name="password" type="password" placeholder="******" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">登录密码</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input name="password_again" type="password" placeholder="******" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">登录密码</div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline">
                <input type="text" name="mobile" placeholder="" value="{{d.entity.mobile||''}}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" placeholder="" class="layui-input" value="{{d.entity.email||''}}">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" data-before="beforeSubmit" lay-submit data-url="/system/user/form"
                    lay-filter="submit" class="layui-btn layui-btn-normal">
                    {{d.entity.id?'保存':'添加'}}
                </button>
            </div>
        </div>



    </form>
</template>


<script>
    layui.use(['app', 'md5', 'func', 'api'], function () {
        const { app, md5, func, api } = layui;
        app({
            data: {
                entity: {
                    sex: 1,
                }
            },
            config: {
                assign: false
            },
            beforeRender: async function () {
                this.entity = (await api("/system/user/form")).data.entity;

            },
            afterRender: function () {

            },
            methods: {
                beforeSubmit: function (data) {
                    data.roleId = this.entity.roleId;
                    data.id = this.entity.id;
                    if (data.password.trim().length > 0) {
                        data.password = md5.exec(data.password);
                    }
                    return data;
                },
            }
        })
    });
</script>